package com.douwong.student.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.douwong.student.R;
import com.douwong.student.model.ClassFile;
import com.douwong.student.model.ClassFileBean;
import com.douwong.student.view.MyGridView;

import java.util.ArrayList;

public class ClassFileAdapter extends BaseAdapter {

	private ArrayList<ClassFileBean> list;
	private Context context;

	public ClassFileAdapter(ArrayList<ClassFileBean> list, Context context) {
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if (convertView == null) {
			holder = new Holder();
			convertView = LayoutInflater.from(context).inflate(R.layout.class_file_item, null);
			holder.time = (TextView) convertView.findViewById(R.id.time);
			holder.pic_gridview = (MyGridView) convertView.findViewById(R.id.pic_gridview);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		ArrayList<ClassFile> temp = new ArrayList<ClassFile>();
		if (list.size() > 0) {
			temp.addAll(list.get(position).getList());
			holder.time.setText(list.get(position).getCreateTime().substring(0, 10));
		}
		ClassFileInnerAdapter adapter = new ClassFileInnerAdapter(temp, context);
		holder.pic_gridview.setAdapter(adapter);
		return convertView;
	}

	class Holder {
		TextView time;
		MyGridView pic_gridview;
	}

}
